package karaoke.servlets;

import java.io.IOException;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import karaoke.excepcion.DAOExcepcion;
import karaoke.modelo.Sala;
import karaoke.negocio.GestionSala;

/**
 * Servlet implementation class RegistrarSalaServlet
 */
@WebServlet("/RegistrarSalaServlet")
public class RegistrarSalaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegistrarSalaServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		GestionSala negocio = new GestionSala();
		
		try {
			
			String nombresala = request.getParameter("txtnomsala");
			int capacidad = Integer.parseInt(request.getParameter("txtcapa"));
			String dsc = request.getParameter("txtDescripcion");
			int clocal = Integer.parseInt(request.getParameter("cboLocal"));
			
			if (nombresala != null && capacidad != 0 && dsc!=null && clocal!=0)
			{
				//Producto prod = 
				negocio.insertar(clocal,nombresala,capacidad,dsc);
				//request.setAttribute("CODIGONUEVO", prod.getCodigo());
				//RequestDispatcher rd = request.getRequestDispatcher("Producto.jsp");
				//rd.forward(request, response);
							
				Collection<Sala> listado = negocio.buscarPorNombre("");
				request.setAttribute("LISTASALAS",listado);	
				RequestDispatcher rd = request.getRequestDispatcher("BuscarSalas.jsp");
				rd.forward(request, response);
				
				//response.sendRedirect("BuscarProductos.jsp");
			}
		} catch (DAOExcepcion e) {
			e.printStackTrace();
		}
	}

}
